﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace SharedLib.Helpers
{
    public static class Input
    {
        private static KeyboardState _lastKeyboardState;
        private static KeyboardState _currentKeyboardState;
        private static MouseState    _currentMouseState;
        private static MouseState    _lastMouseState;

        public static bool isPressed(Keys k)
        {
            if(Input._currentKeyboardState.IsKeyDown(k))
            {
                if (Input._lastKeyboardState.IsKeyUp(k))
                    return true;
            }
            return false;
        }

        public static bool isRelease(Keys k)
        {
            if (Input._currentKeyboardState.IsKeyUp(k))
            {
                if (Input._lastKeyboardState.IsKeyDown(k))
                    return true;
            }
            return false;
        }

        public static bool isHold(Keys k)
        {
            if (Input._currentKeyboardState.IsKeyDown(k))
                return true;
            return false;
        }

        public static bool LeftMousePressed()
        {
            if (Input._currentMouseState.LeftButton == ButtonState.Pressed && Input._lastMouseState.LeftButton == ButtonState.Released)
                return true;
            else
                return false;
        }

        public static MouseState getMouse()
        {
            return Input._currentMouseState;
        }

        public static KeyboardState getKeyboard()
        {
            return Input._currentKeyboardState;
        }

        public static void Update(GameTime gameTime)
        {
            Input._lastKeyboardState    = Input._currentKeyboardState;
            Input._currentKeyboardState = Keyboard.GetState();

            Input._lastMouseState    = Input._currentMouseState;
            Input._currentMouseState = Mouse.GetState();
        }

        public static MouseState getLastMouseState()
        {
            return _lastMouseState;
        }

        public static KeyboardState getLastKeyboardState()
        {
            return _lastKeyboardState;
        }
    }
}
